<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Todo App</title>
    <link rel="stylesheet" href="./Link/Link.css">
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style>
        .item {
            margin-top: 10px;
            padding: 10px;
            background-color: #f0f0f0;
            border-radius: 5px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
    </style>
</head>
<body>
    <div class="box1">
        <h1>Todo App</h1>
        <div class="tx">
            <input 
                type="text" 
                id="AddTodo" 
                v-model="inputValue" 
                @keyup.enter="addItem"
                placeholder="Add todo" 
            >
            <button @click="addItem">Add todo</button>
        </div>
        <div v-for="(item,index) in item" :key="index" class="item">{{item}}</div>
    </div>
    <script>
        let AddTodo = new Vue({
            el:'.box1',
            data: {
                inputValue:'',
                item:[]
            },
            methods: {
                addItem(){
                    if(this.inputValue.trim()!==''){
                        this.item.push(this.inputValue)
                        this.inputValue = ''; // 清空输入框
                    }
                }
            }
        })
    </script>
</body>
</html>
